<template>
  <div id="root">

    <ChangeLogin></ChangeLogin>

  <div class="login-user">
    <div class="login-ton">
      <h1>login</h1>
    </div>
    <!-- <label for="用户名">
        用户名:
            <input type="text" placeholder="请输入用户名">
    </label>


        <p><label for="密码">密码：
            <input type="text" placeholder="请输入密码">
        </label>
    </p> -->
    <div class="user">
      <input type="text" v-model="LoginData.userName" placeholder="username">
    </div>

    <div class="pass">
      <input type="text" v-model="LoginData.password" placeholder="password">
    </div>

    <div class="reg">注册</div>
    <div>
      <button @click="toHome">登录</button>
    </div>
  </div>

  </div>
</template>

<script>
import ChangeLogin from "./ChangeLogin";
export default {
  name: "Login_CaoMengYao",
  components: {ChangeLogin},
  data(){
    return{
      LoginData:{
        userName:'',
        password:'',
      },
      //注册的数据
      SignData:{
        username:'',
        password:'',
        nickname:'',
        phone:'',
        code:''
      },
    }
  },

  methods:{
    //登录
    toHome(){
      this.axios.post('/user/login',this.LoginData).then(res=>{
        //登录成功的时候，保存username到浏览器
        // console.log(res)
        if(res.data.code==200){
          localStorage.setItem('token',res.data.data.token)
          localStorage.setItem('userName',this.LoginData.userName)
          localStorage.setItem('password',this.LoginData.password)
          // console.log(res)
          this.$message.success('登录成功')
          this.$router.push('/Home')
        }
        else this.$message.warning('登录密码错误')
      }).catch(()=>{
        this.$message.warning('登录密码错误')
      })
    },
    //注册
    toSign(){
      console.log("开始注册")
      // console.log(this.SignData)
      this.axios.post('/Logon',{},{params:this.SignData}).then(res=>{
        console.log(res)
        console.log(this.SignData)
        if(res.data.code=='400'){
          this.$message.error('验证码错误')
        }
        else if(res.data==''){
          this.$message.error('注册失败')
        }
        else if(res.data.code=='200'){
          this.$message.success('注册成功')
          this.LoginData.userName=this.SignData.username
          this.LoginData.password=this.SignData.password
          this.toHome()
        }
      }).catch(()=>{
        this.$message.warning('注册失败，该账号已被注册')
      })
    },
  }
}
</script>

<style scoped>

#root{
  height: 100%;
  background-image: url(../assets/背景图片1.jpg);
  position: absolute;
}

.login-user {
  width: 400px;
  height: 300px;
  margin: auto;
  margin-top: 200px;
  text-align: center;
  background: rgba(0,0,0,0.4);
  border-radius: 1em;

}

.login-user:hover h1{
  color: bisque;
  /* box-shadow: 0 0 2px 2px rgba(0,0,0,0.3); */
}

button:hover{
  cursor: pointer;
}

.login-user:hover{
  /* color: bisque; */
  box-shadow: 0 0 2px 2px rgba(0,0,0,0.3);
}

h1 {
  font-size: 50px;
  margin: 10px;
  color: rgb(255, 253, 240);
}

div input {
  width: 200px;
  height: 35px;
  margin: 15px;

  background-color: rgba(0, 0, 0,0);
  border: 0;
  outline: none;
  /* opacity: 0; */
  border-bottom: 2px solid #fff;
  font-size: 20px;
  color: #fff;
}
/* reg { */
/* width: 10px;
height: 5px;
font-size: 5px;
background-color: transparent;
text-align: right; */
/* margin-top: 10px;
border-radius: 1em;
border: 1px solid #fff; */
/* }  */
.login-user>div button {
  width: 150px;
  height: 35px;
  font-size: 18px;
  background-color: transparent;
  margin-top: 10px;
  border-radius: 1em;
  border: 1px solid #fff;
}

</style>